package com.sudoku.listener;

import java.awt.event.WindowEvent;

import com.sudoku.common.Constants;
import com.sudoku.common.SqliteUtils;
import com.sudoku.ui.Sudoku;

public class WindowActionListener implements java.awt.event.WindowListener {

	private Sudoku sudoku;
	
	public WindowActionListener(Sudoku sudoku) {
		this.sudoku = sudoku;
	}
	
	@Override
	public void windowClosing(WindowEvent e) {
		if (Constants.LABEL_PUZZLE.equals(sudoku.getAtCard())) {
			SqliteUtils.insert(sudoku);
		}
		
		/**
		 * 关闭数据库链接
		 */
		SqliteUtils.closeConnection();
		System.exit(0);
	}
	
	@Override
	public void windowOpened(WindowEvent e) {}

	@Override
	public void windowClosed(WindowEvent e) {}

	@Override
	public void windowIconified(WindowEvent e) {}

	@Override
	public void windowDeiconified(WindowEvent e) {}

	@Override
	public void windowActivated(WindowEvent e) {}

	@Override
	public void windowDeactivated(WindowEvent e) {}

}
